<?php
require_once __DIR__.'/VoteConst.php';
require_once __DIR__.'/logic/VoteImpl.php';

final class VoteExport
{
	/**
	 * add Vote
	 * @param int $type type
	 * @param string $name vote name
	 * @param array  $data
	 * <code>array(
	 * 	'vote_summary',
	 * 	'vote_cover',
	 * 	'vote_allow_num',
	 * 	'user_id',
	 * 	'access_type',
	 * 	'access_begin',
	 * 	'access_stop',
	 * 	'access_token',
	 * 	'create_ip',
	 * )</code>
	 * @return array(
	 *   'id',
	 *   'guid',
	 * )
	 */
	function addVote($type, $name, array $data)
	{
		return VoteImpl::addVote($type, $name, $data);
	}


	/**
	 * get the vote
	 * @param  int | string $voteId the vote_id or vote_guid
	 * @return array | false
	 */
	function getVote($voteId)
	{
		return VoteImpl::getVote($voteId);
	}

	/**
	 * update the vote
	 * @param  int | string $voteId [description]
	 * @param  array  $data   [description]
	 */
	function updateVote($voteId, array $data)
	{
		unset($data['access_token']);
		VoteImpl::updateVote($voteId, $data);
	}

	/**
	 * reset the vote's access token
	 * @param  int | string $voteId [description]
	 * @return [type]         [description]
	 */
	function resetAccessToken($voteId)
	{
		VoteImpl::resetAccessToken($voteId);
	}

	/**
	 * delete the vote
	 * @param  int | string $voteId [description]
	 */
	function delVote($voteId)
	{
		VoteImpl::updateVote($voteId, array('vote_status' => -1));
	}

	/**
	 * forbidden the vote
	 * @param  int | string  $voteId    [description]
	 * @param  boolean $forbidden [description]
	 */
	function forbiddenVote($voteId, $forbidden = true)
	{
		VoteImpl::updateVote($voteId, array('vote_status' => $forbidden ? 0 : 1));
	}
}
